def frozen(set):
    "Raise an error when trying to set an undeclared name."
    def set_attr(self,name,value):
        if hasattr(self,name):
            set(self,name,value) 
        else:
            raise AttributeError("You cannot add attributes to %s" % self)
    return set_attr

class Frozen(object):
    """Subclasses of Frozen are frozen, i.e. it is impossibile to add
     new attributes to them and their instances."""
    __setattr__=frozen(object.__setattr__)
    class __metaclass__(type):
        __setattr__=frozen(type.__setattr__)

class Person(Frozen):
    firstname=""
    lastname=""
    def __init__(self,firstname,lastname):
        self.firstname=firstname
        self.lastname=lastname

Person.firstname=""
me=Person("Michele","Simionato")
#Person.add_an_attribute="something"
me.add_an_attribute="something" 
